//通过vue-router插件实现模板路由配置
import { createRouter, createWebHistory } from 'vue-router'
import { constantRoute } from './router'

//创建路由器
const router = createRouter({
	history: createWebHistory(import.meta.env.BASE_URL),
	routes: constantRoute,
	scrollBehavior(to, from, savedPosition) {
		if (to.hash) {
			console.log(to.hash)
			setTimeout(() => {
				const element = document.querySelector(to.hash)
				if (element) {
					// 平滑滚动到元素
					element.scrollIntoView({ behavior: 'smooth' })
				}
			}, 2000);
		}
	}
})
export default router
